﻿
using FixMath.NET;
using GameConfig.slot;
using GameProtocol;
using Google.Protobuf;
using TEngine;
using UnityEngine;

namespace GameLogic
{
    partial class MainUI
    {
        #region 生命周期回调
        protected override void OnCreate()
        {
            base.OnCreate();
            m_btnOnlineLobby.onClick.AddListener(OnClickOnlineLobbyBtn);
            m_btnStartGame.onClick.AddListener(OnClickStartGameBtn);
            m_btnShipConfig.onClick.AddListener(OnClickShipConfigBtn);
            m_btnMap.onClick.AddListener(OnClickMapBtn);
        }

        protected override void OnUpdate()
        {
            base.OnUpdate();   
            if(Input.GetKeyDown(KeyCode.Space))
            {
                GameProtocol.ShipData data = new GameProtocol.ShipData();
                data.CfgID = 10002;
                var cfgD1 = new SlotConfigData();
                cfgD1.EquipmentID = 10000;
                var cfgD2 = new SlotConfigData();
                cfgD2.EquipmentID = 10003;
                data.SlotEquipment.Add(1, cfgD1);
                data.SlotEquipment.Add(2, cfgD2);
                data.Sp = 10;

                GameDataModule.Instance.AddShip(data);
                GameModule.UI.ShowUI<FloatingTips>("Test test!!!!");

                //ShipDesignData j = new ShipDesignData();

                //var slotData1 = new SlotDesignData();
                //slotData1.PosX = 500;
                //slotData1.SlotType = (int)EType.Weapon;
                //slotData1.SlotSize = (int)ESize.Small;
                //var slotData2 = new SlotDesignData();
                //slotData2.PosX = -500;
                //slotData1.SlotType = (int)EType.Weapon;
                //slotData1.SlotSize = (int)ESize.Small;
                //j.SlotDesignDatas.Add(1, slotData1);
                //j.SlotDesignDatas.Add(2, slotData2);

                //var bytes = j.ToByteArray();
                ////var root = j.Serialize();
                //UtilsUnity.SaveFile(bytes, "C:/Code/mm.datas");
            }
        }
        #endregion

        #region UI回调
        void OnClickStartGameBtn()
        {
            GameEvent.Send(GameEventType.OnStartGame);

        }
        void OnClickOnlineLobbyBtn()
        {
            GameEvent.Send(GameEventType.OnOnlineLobbyClicked);
        }
        void OnClickShipConfigBtn()
        {
            GameModule.UI.ShowUI<ShipConfigUI>();
        }
        void OnClickMapBtn()
        {
            GameModule.UI.ShowUI<SolarSystemMapUI>();
        }
        #endregion
    }
}